<?php
/**
 * 上传广告规则
 *
 * @author Zeon <scplay@gmail.com>
 * @date 2018/9/7 10:47
 * @copyright PanxSoft Inc.
 */

namespace App\Http\Requests\Concerns;




use App\Models\Panx\Product;
use App\Models\Store\Pack;
use App\Models\Url;
use Illuminate\Validation\Rule;

trait AdvertRule
{
    protected function redirectableRules()
    {
        $url_basename = class_basename(Url::class);

        return [
            'redirectable_id' => 'int|min:0',
            'redirectable_type' => [
                'string',
                Rule::in([
                    class_basename(Product::class),
                    class_basename(Pack::class),
                    $url_basename,
                ])
            ],
            'redirect_url' => 'required_if:redirectable_type,'. $url_basename  .'|url',
        ];
    }
}